package com.msb.mall.producet.web;

import com.msb.mall.producet.entity.CategoryEntity;
import com.msb.mall.producet.service.CategoryService;
import com.msb.mall.producet.vo.Catalog2VO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @Author zhangjiajun
 * @Email zhangjiajun@hydsoft.com
 * @Description
 * @Date 2025/7/24 12:43
 */
@Controller
public class IndexController {

    @Autowired
    CategoryService categoryService;

    @GetMapping({"/","/home","/index"})
    public String index(Model model) {
        //查询出所有一级分类的信息
        List<CategoryEntity> categoryLevel1 = categoryService.getLevel1Category();
        model.addAttribute("categorys", categoryLevel1);

        //classPath:/templates/
        //.html
        return "index";
    }

    //index/catalog.json
    @ResponseBody
    @RequestMapping("/index/catalog.json")
    public Map<String, List<Catalog2VO>> getCategoryToJson() {

        Map<String, List<Catalog2VO>> data = categoryService.getCatalog2JSON();

        return data;
    }
}
